package net.da.core.manager;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;

public class ApplicationSessionIdManager {

    // This is an utility class do not instantiate
    private ApplicationSessionIdManager() {
    }

    /**
     * Generate the session id for the given user id.
     */
    public String generateAuthorizationCode(Integer userId) {
        long n = (long) (Math.random() * Long.MAX_VALUE);
        return encode(Long.toString(n) + Integer.toString(userId) + Long.toString(System.currentTimeMillis()));
    }

    private String encode(String code) {
        byte[] digest = DigestUtils.sha(code);
        return new String(Base64.encodeBase64(digest));
    }

    /**
     * Delete the timed out sessions.
     *
     */
    public void deleteTimedOutSessions() {



    }
}
